﻿Imports System.Linq
Imports TNCDAL

Public Class FileController
    Private objRepository As New FileRepository

    Public Function SelectAllRecord() As IQueryable(Of tblFile)
        Return objRepository.SelectAllRecord()
    End Function

    Public Function SelectRecordById(ByVal id As Integer) As tblFile
        Return objRepository.SelectRecordById(id)
    End Function

    Public Function Insert(ByVal obj As tblFile) As tblFile
        Return objRepository.Insert(obj)
    End Function

    Public Sub Update(ByVal obj As tblFile)
        objRepository.Update(obj)
    End Sub

    Public Function IsExistFileNo(ByVal isExport As Boolean, ByVal fileNo As String) As Boolean
        Return objRepository.IsExistFileNo(isExport, fileNo)
    End Function

    Public Function InsertByCopyFile(ByVal obj As tblFile) As tblFile
        Return objRepository.InsertByCopyFile(obj)
    End Function

    Public Sub Delete(ByVal obj As tblFile)
        'Xóa File (xóa luôn FileMBL)
        objRepository.Delete(obj)
        'Xóa File sẽ phải xóa: Cont, FileMBL, FileFee của File
        'Xóa FileMBL sẽ phải xóa: HBL của MBL
        'Xóa HBL sẽ phải xóa: HBLFee (Cont theo HBL đã xóa trước đó)
        'Xóa các phiếu thu chi liên quan đến ContFee
        'Xóa các phiếu thu chi liên quan đến FileFee (Giá mua theo MBL)
        'Xóa các phiếu thu chi liên quan đến SellingFee (Giá bán theo HBL)

    End Sub


    Public Sub Cancel(ByVal obj As tblFile, ByVal isCancel As Boolean)
        objRepository.Cancel(obj, isCancel)
    End Sub

    'Public Function SelectAllRecord(ByVal isExport As Boolean) As IQueryable(Of tblFile)
    '    Return objRepository.SelectAllRecord(isExport)
    'End Function
   
    'Public Function SelectCustomAllRecord(ByVal isExport As Boolean) As IQueryable
    '    Return objRepository.SelectCustomAllRecord(isExport)
    'End Function

    ''' <summary>
    ''' Select records with conditions
    ''' </summary>
    ''' <param name="isExport"></param>
    ''' <param name="strCustomer"></param>
    ''' <param name="strCompany"></param>
    ''' <param name="strForeignCompany"></param>
    ''' <param name="D2DValue"></param>
    ''' <param name="FCLValue"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function SelectCustomAllRecord(ByVal isExport As Boolean, _
                                          ByVal D2DValue As Integer, _
                                          ByVal FCLValue As Integer, _
                                          ByVal strFileNo As String, _
                                          ByVal strCustomer As String, _
                                          ByVal strCompany As String, _
                                          ByVal strForeignCompany As String, _
                                          ByVal strAgent As String, _
                                          ByVal strNoiHaCont As String, _
                                          ByVal strNoiNangCont As String, _
                                          ByVal strTerm As String, _
                                          ByVal strOtherCurrency As String, _
                                          ByVal strLineBookingNo As String, _
                                          ByVal strMBLNo As String, _
                                          ByVal strLine As String, _
                                          ByVal strVessel As String, _
                                          ByVal strVoyageNo As String, _
                                          ByVal strPOL As String, _
                                          ByVal strPOD As String, _
                                          ByVal strTransPort As String, _
                                          ByVal dtETDFrom As DateTime, _
                                          ByVal dtETDTo As DateTime, _
                                          ByVal dtETAFrom As DateTime, _
                                          ByVal dtETATo As DateTime, _
                                          ByVal isMaster As Integer, _
                                          ByVal isCareOf As Integer, _
                                          ByVal strHBLNo As String, _
                                          ByVal strConditionCBM_HBL As String, _
                                          ByVal valueCBM_HBL As Double, _
                                          ByVal strConditionNW_HBL As String, _
                                          ByVal valueNW_HBL As Double, _
                                          ByVal strConditionGW_HBL As String, _
                                          ByVal valueGW_HBL As Double, _
                                          ByVal strNotifyParty As String, _
                                          ByVal strMarksAndNumbers As String, _
                                          ByVal strGoodDescription As String, _
                                          ByVal strContNo As String, _
                                          ByVal strContType As String, _
                                          ByVal strSeal As String, _
                                          ByVal strTypeOfGood As String, _
                                          ByVal strPackage As String, _
                                          ByVal strConditionCBM_Cont As String, _
                                          ByVal valueCBM_Cont As Double, _
                                          ByVal strConditionNW_Cont As String, _
                                          ByVal valueNW_Cont As Double, _
                                          ByVal strConditionGW_Cont As String, _
                                          ByVal valueGW_Cont As Double, _
                                          ByVal strContNote As String) As IQueryable
        Return objRepository.SelectCustomAllRecord(isExport, D2DValue, FCLValue, _
                                                   strFileNo, strCustomer, strCompany, strForeignCompany, strAgent, _
                                                   strNoiHaCont, strNoiNangCont, _
                                                   strTerm, strOtherCurrency, _
                                                   strLineBookingNo, strMBLNo, strLine, strVessel, strVoyageNo, _
                                                   strPOL, strPOD, strTransPort, _
                                                   dtETDFrom, dtETDTo, dtETAFrom, dtETATo, _
                                                   isMaster, isCareOf, _
                                                   strHBLNo, _
                                                   strConditionCBM_HBL, valueCBM_HBL, strConditionNW_HBL, valueNW_HBL, strConditionGW_HBL, valueGW_HBL,
                                                   strNotifyParty, strMarksAndNumbers, _
                                                   strGoodDescription, strContNo, strContType, strSeal, strTypeOfGood, strPackage, _
                                                   strConditionCBM_Cont, valueCBM_Cont, strConditionNW_Cont, valueNW_Cont, strConditionGW_Cont, valueGW_Cont, _
                                                   strContNote)
    End Function

    ''' <summary>
    ''' Lấy số file khi tạo mới lô hàng
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetNewOrderNum(ByVal isExport As Boolean) As Integer
        Return objRepository.GetNewOrderNum(isExport)
    End Function
End Class
